using System;
using System.Data;
using Framework.Library;
using Framework.Library.Components.Commands;
using Framework.Library.Components.Roles;
using Framework.Library.Components.Security;
using Framework.Library.Components.Users;
using Framework.Library.Components.Providers;
using Framework.Library.Utilities;

namespace Framework.WebControls
{
	/// <summary>
	/// Summary description for ButtonRoleViewAll.
	/// </summary>
	public class ButtonRoleAdd : System.Web.UI.WebControls.Button
	{
        protected bool pmsRole;
        protected bool pmsRole1;

        private AuthenticatedPage CurrentPage
		{
            get { return (AuthenticatedPage)this.Page; }
		}

        protected UserInfo CurrentUser
		{
			get { return CurrentPage.CurrentUser; }
		}

		protected override void OnPreRender(EventArgs e)
		{
		    DataTable dt = CommandController.GetButtonRoleForUserByPortalID(CurrentUser.UserID, ConvertUtility.ToInt32(AppEnv.PortalId()));

            if(dt.Rows.Count >0)
            {
                if (dt.Rows.Count > 1)
                {
                    pmsRole = ConvertUtility.ToBoolean(dt.Rows[0]["Role_Add"]);
                    pmsRole1 = ConvertUtility.ToBoolean(dt.Rows[1]["Role_Add"]);

                    if (!pmsRole && !pmsRole1)
                    {
                        this.Visible = false;
                    }
                    else
                    {
                        this.Visible = true;
                    }
                }
                else
                {
                    pmsRole = ConvertUtility.ToBoolean(dt.Rows[0]["Role_Add"]);
                    if (!pmsRole)
                    {
                        this.Visible = false;
                    }
                    else
                    {
                        this.Visible = true;
                    }
                }
            }
            else
            {
                this.Visible = false;
            }
		}
	}
}
